#ifndef __PHLOGGER_ANDROID_H__
#define __PHLOGGER_ANDROID_H__

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <stdarg.h>


#ifdef WRITE_LOG_TO_FILE
#include "flogger.h"
#else
#include <android/log.h>
#endif

#ifndef LOG_TAG
#define LOG_TAG "AndroidSunlogin"
#endif


/*
typedef enum android_LogPriority {
    ANDROID_LOG_UNKNOWN = 0,
    ANDROID_LOG_DEFAULT,    // only for SetMinPriority()
    ANDROID_LOG_VERBOSE,
    ANDROID_LOG_DEBUG,
    ANDROID_LOG_INFO,
    ANDROID_LOG_WARN,
    ANDROID_LOG_ERROR,
    ANDROID_LOG_FATAL,
    ANDROID_LOG_SILENT,     // only for SetMinPriority(); must be last
} android_LogPriority;
*/

#ifndef DISENABLE_LOGGER

#  ifdef WRITE_LOG_TO_FILE

    #define SetLogPath flogger::GetInitance().Path
    #define OpenLogger flogger::GetInitance().open
    #define SetLogFlag flogger::GetInitance().Flag
    #define LoadFromCFG flogger::GetInitance().loadcfg
    #define SetMaxSize flogger::GetInitance().MaxSize
    #define EnableLogger flogger::GetInitance().enable_logger
    #define SetLogSpliter flogger::GetInitance().Split
    #define WriteLog flogger::GetInitance().write_log

    inline void SetLoggerPipe(const char*){}
    inline void CloseLoggerPipe(){}

#  else // WRITE_LOG_TO_FILE

    inline bool  WriteLog(LOG_FLAG evt,const char* str,...)
    {
        int priority = ANDROID_LOG_VERBOSE; // default value
        if (LOG_INFO == evt) priority = ANDROID_LOG_INFO;
        else if(LOG_WARNING == evt) priority = ANDROID_LOG_WARN;
        else if (LOG_ERROR == evt) priority = ANDROID_LOG_ERROR;
        else if (LOG_DEBUG == evt) priority = ANDROID_LOG_DEBUG;
        // level filter
        if (priority  < ANDROID_LOG_INFO) return false;
        // 打印日志
        va_list   varg;
        va_start(varg,   str);
    #ifdef _WRITE_LOG_TO_CONSOLE
        vprintf(str, varg);
        printf("\n");
    #else
        __android_log_vprint(priority, LOG_TAG, str, varg);
    #endif
        va_end(varg);

        return true;
    }

    inline void OpenLogger(const char*){}
    inline void EnableLogger(bool){}
    //#define WriteLog WriteAndroidLogString
    inline void SetLoggerPipe(const char*){}
    inline void CloseLoggerPipe(){}
    inline void SetMaxSize(unsigned long) {}
    inline void SetLogPath(const char*){}
    inline void SetLogFlag(int){}

#  endif // WRITE_LOG_TO_FILE

#else //DISENABLE_LOGGER

    inline void OpenLogger(const char*){}
    inline void EnableLogger(bool){}
    inline void WriteLog(LOG_FLAG evt,const char* str,...){}
    inline void SetLoggerPipe(const char*){}
    inline void CloseLoggerPipe(){}
    inline void SetMaxSize(unsigned long) {}
    inline void SetLogPath(const char*){}
    inline void SetLogFlag(int){}

#endif //DISENABLE_LOGGER

#endif //__PHLOGGER_H__
